package com.bTrace;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 描述:
 *
 * @author luzhongfu
 * Created by lucky on 2020-08-31 4:27 PM
 */
public class DeadLock {

    private Object object1 = new Object();

    private Object object2 = new Object();

    public void run1(){
        synchronized (object2){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (object1){
                System.out.println("run1");
            }
        }
    }

    public void run2(){
        synchronized (object1){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (object2){
                System.out.println("run2");
            }
        }
    }

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        DeadLock deadLock = new DeadLock();
        for (int i = 0 ; i < 100 ; i++){
//            deadLock.run1();
//            deadLock.run2();
            executorService.execute(()->deadLock.run1());
            executorService.execute(()->deadLock.run2());
        }
    }
}
